package com.study.d11_tcp_mul2;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ServerReaderThread extends Thread{
    private Socket socket;
    public ServerReaderThread(Socket socket){
        this.socket=socket;
    }

    @Override
    public void run() {
        try {
            InputStream inputStream = socket.getInputStream();
            DataInputStream dis = new DataInputStream(inputStream);
            while(true){
                try{
                    String msg = dis.readUTF();
                    System.out.println(msg);
                }catch (Exception e) {
                    System.out.println(socket.getRemoteSocketAddress()+"下线了");
                    inputStream.close();
                    dis.close();
                    break;
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
